const Com = require("../gmoon/baseCom");
cc.Class({
    extends: Com,

    properties: {
    },

    ctor(){
        this.__items = [];
        this._shoot_rate = [.3 , .5 , 1 , 1.3 , 1.6];
        this._shoot_onoff = 1;
    },

    _addItem( item ){
        this.__items = this.__items || [];
        this.__items.push(item);
    },

    resetPos(){
        this.__items = this.__items || [];
        for(let i in this.__items){
            $T.getScr(this.__items[i]).resetGunpos();
        }
        let bigpaoItem = $T.findChildNode("paotaibig" , this.node.parent);
        $T.getScr(bigpaoItem).resetGunpos();
    },

    unload(){
        let bigpaoItem = $T.findChildNode("paotaibig" , this.node.parent);
        let bigGun = $T.getScr(bigpaoItem).getGun();
        bigGun && (bigGun.node.active = false);
    },

    loadItems(){
        const size = cc.winSize;
        const num = [[0,100] , [-10,60], [+10,60]] , padding=10 , margin=15;
        const width = 130 , height=125;//(size.width - padding*2 - margin*(num.length-1))/num.length;
        let item , gun , x,y , nodeSize , ars=[];
        const sprite = $RES.g("img-ptitm-bg");

        item = $RES.createPrefab("fab-pt-item");
        nodeSize = $T.setNodeSize( this.node , [(width + margin) * num.length , (item.height+margin)] )

        for(let i=0; i<num.length; i++){
            gun = $G.get('poolGetByName' , 'gun');//$RES.createPrefab("fab-gun");
            $T.getScr(gun).setLevel(1);
            $T.setNodeSize( gun , [,160]);
            
            $T.setSprite( item , sprite , [width,] );
            x = $T.compListPoxV( 0 , i , width+margin , num.length , -1);
            y = 0;//height;
            item.x = x, item.y = y;
            item.parent = this.node;

            this._addItem(item);
            // (( itm , gn )=>{
            //     setTimeout(() => {
            //         $T.getScr(itm).fitGun( gn );
            //     }, 500);
            // })( item , gun )
            $T.getScr(item).fitGun( gun );
            item = $RES.createPrefab("fab-pt-item");
        }
        return nodeSize;
    }
});
